#pragma once
#include "Types.h"
#include "ChunkSliceInfo.h"
#include <boost\shared_ptr.hpp>
#include <boost\shared_array.hpp>
#define CHUNK_INDEX(x,z,y) (x + (z * Chunk::xBlocks) + (y * Chunk::blockSingleSliceLength))
#define CHUNKSLICE_INDEX(x,z,y,slice) (x + (z * Chunk::xBlocks) + (slice * Chunk::chunkHSliceLength) + (y * Chunk::blockSingleSliceLength))
typedef boost::shared_array<uint> Shared_BlockBuffer;
typedef boost::shared_array<ChunkSliceInfo> Shared_SliceInfo;

class BlockRenderer;
class ChunkManager;
class Chunk
{
public:
	Chunk(ChunkManager *pChunkManager, int x, int z);
	~Chunk(void);
	void Generate();
	void Draw(BlockRenderer *blockRenderer);
	bool CanUnload() { return m_bAllowUnload; };
private:
	Shared_BlockBuffer m_blockIndex;
	Shared_SliceInfo m_sliceInfo;

	bool m_bAllowUnload;
	int m_nXPos;
	int m_nZPos;
	ChunkManager *m_pChunkManager;

public:
	//Constant chunk format
	const static uint xBlocks = 16;
	const static uint zBlocks = 16;
	const static uint yBlocks = 512;
	const static uint blockDataLength = xBlocks * yBlocks * zBlocks;
	const static uint blockSingleSliceLength = xBlocks * zBlocks;
	const static uint chunkHSliceCount = 32;
	const static uint chunkHSliceHeight = (uint)(yBlocks/chunkHSliceCount);
	const static uint chunkHSliceLength = blockSingleSliceLength * chunkHSliceHeight;
};

